package org.yxj.yxjtextureview;

import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import org.yxj.videolibrary.util.SubmergedBarUtil;
import org.yxj.videolibrary.util.YXJVideoManager;
import org.yxj.videolibrary.view.YXJVideoView;


public class MainActivity extends AppCompatActivity {

    private FrameLayout container;
//    private String videoUrl = "http://vod.cntv.lxdns.com/flash/mp4video61/TMS/2017/08/17/63bf8bcc706a46b58ee5c821edaee661_h264818000nero_aac32-5.mp4";
//    private String imgUrl = "https://imgcps.jd.com/ling4/1768313/5Lqs6YCJ5aW96LSn/5L2g5YC85b6X5oul5pyJ/p-5f3a47329785549f6bc7a6f6/3450444f/cr/s/q.jpg";
    private String videoUrl = "https://i.zhaojinapp.com/ProductImage/2308/30/2308301621012139.mp4";
    private String imgUrl = "https://i.zhaojinapp.com/ProductImage/2206/20/2206201613283556.jpg";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SubmergedBarUtil.submergedBar(this);
        addVideo();

        findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                yxjVideoManager.closeAudio(MainActivity.this);
            }
        });
        findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                yxjVideoManager.openAudio(MainActivity.this);
            }
        });

        findViewById(R.id.btn3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                yxjVideoManager.getYxjVideoView().setScreenSizeStyle(YXJVideoView.ScreenSizeStyle.widthFull);
                yxjVideoManager.getYxjVideoView().showScreenSizeStyle();
            }
        });

        findViewById(R.id.btn4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                yxjVideoManager.getYxjVideoView().setScreenSizeStyle(YXJVideoView.ScreenSizeStyle.heightFull);
                yxjVideoManager.getYxjVideoView().showScreenSizeStyle();
            }
        });
    }


    YXJVideoManager yxjVideoManager = new YXJVideoManager() ;

    private void addVideo() {
        container = findViewById(R.id.content);
        Button button = new Button(this);
        button.setText("测试");
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL ;
        yxjVideoManager.addChildView(button,layoutParams,new Rect(0,0,0,120)) ;
        yxjVideoManager.init(this,container);
        yxjVideoManager.getYxjVideoView().setAutoScreenSizeStyle(false);
        yxjVideoManager.getYxjVideoView().setScreenSizeStyle(YXJVideoView.ScreenSizeStyle.widthFull);
        yxjVideoManager.getYxjVideoView().setAutoPlay(false);
        yxjVideoManager.getYxjVideoView().setBgColor(Color.BLACK);
        yxjVideoManager.setData(videoUrl,imgUrl);
    }


    @Override
    protected void onResume() {
        super.onResume();
        yxjVideoManager.closeAudio(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        yxjVideoManager.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        yxjVideoManager.onDestroy();
    }
}